package dongze.com.ckdj.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.BindView;
import butterknife.ButterKnife;
import dongze.com.ckdj.R;
import dongze.com.ckdj.fragment.BaseFragment;
import dongze.com.ckdj.fragment.CheckInRecordFragment;
import dongze.com.ckdj.fragment.MassLossRecordFragment;

/**
 * Created by fanqwz on 2017/9/26.
 */

public class CheckInRecordActivity extends BaseFragment {
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    private View view;
    private PagerAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.activity_check_in_record,container,false);
        ButterKnife.bind(this,view);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        adapter = new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public int getCount() {
                return 2;
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == ((Fragment) object).getView();
            }

            @Override
            public Fragment getItem(int position) {
                switch (position) {
                    case 1:
                        return new CheckInRecordFragment();

                    case 0:
                        return new MassLossRecordFragment();

                    default:
                        return null;
                }
            }

            @Override
            public CharSequence getPageTitle(int position) {
                switch (position) {
                    case 1:
                        return getResources().getString(R.string.check_in);

                    case 0:
                        return getResources().getString(R.string.massloss);

                    default:
                        return null;
                }
            }
        };
        viewPager.setAdapter(adapter);

    }


}
